{% extends 'base.html' %}
{% load static %}

{% block title %}积分记录 - Meet活动聚{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row">
        <div class="col-12">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{% url 'home' %}">首页</a></li>
                    <li class="breadcrumb-item"><a href="{% url 'points:points_home' %}">我的积分</a></li>
                    <li class="breadcrumb-item active">积分记录</li>
                </ol>
            </nav>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">积分记录</h5>
                </div>
                <div class="card-body">
                    {% if records %}
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>时间</th>
                                    <th>类型</th>
                                    <th>积分变动</th>
                                    <th>描述</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for record in records %}
                                <tr>
                                    <td class="text-nowrap">{{ record.created_at|date:"Y-m-d H:i" }}</td>
                                    <td>
                                        <span class="badge bg-{% if record.points > 0 %}success{% else %}danger{% endif %}">
                                            {{ record.get_type_display }}
                                        </span>
                                    </td>
                                    <td>
                                        {% if record.points > 0 %}
                                        <span class="text-success">+{{ record.points }}</span>
                                        {% else %}
                                        <span class="text-danger">{{ record.points }}</span>
                                        {% endif %}
                                    </td>
                                    <td>{{ record.description }}</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>

                    <!-- 分页 -->
                    {% if records.has_other_pages %}
                    <nav aria-label="Page navigation" class="mt-4">
                        <ul class="pagination justify-content-center">
                            {% if records.has_previous %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ records.previous_page_number }}">上一页</a>
                            </li>
                            {% endif %}

                            {% for num in records.paginator.page_range %}
                                {% if records.number == num %}
                                <li class="page-item active">
                                    <a class="page-link" href="?page={{ num }}">{{ num }}</a>
                                </li>
                                {% else %}
                                <li class="page-item">
                                    <a class="page-link" href="?page={{ num }}">{{ num }}</a>
                                </li>
                                {% endif %}
                            {% endfor %}

                            {% if records.has_next %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ records.next_page_number }}">下一页</a>
                            </li>
                            {% endif %}
                        </ul>
                    </nav>
                    {% endif %}

                    {% else %}
                    <div class="text-center py-5">
                        <i class="bi bi-clock-history text-muted display-1"></i>
                        <h4 class="text-muted mt-3">暂无积分记录</h4>
                        <p class="text-muted">快去参与活动获取积分吧！</p>
                        <a href="{% url 'activities:activity_list' %}" class="btn btn-primary me-2">去参与活动</a>
                        <a href="{% url 'points:points_home' %}" class="btn btn-outline-primary">返回积分首页</a>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}